﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Newtonsoft.Json;

namespace AliyunOpenSearch4Net.Base
{
    /// <summary>
    /// the interface for named item
    /// </summary>
    public interface INamedItem
    {
        /// <summary>
        /// Gets the name.
        /// </summary>
        /// <value>
        /// The name.
        /// </value>
        string Name { get; }

        /// <summary>
        /// Gets the item data.
        /// </summary>
        /// <value>
        /// The item data.
        /// </value>
        object Item { get; }
    }

    /// <summary>
    /// The named item's implementation
    /// </summary>
    /// <typeparam name="TItem">The type of the item.</typeparam>
    public class NamedItem<TItem> : INamedItem
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="NamedItem{TItem}"/> class.
        /// </summary>
        public NamedItem()
        {

        }

        /// <summary>
        /// Initializes a new instance of the <see cref="NamedItem{TItem}"/> class.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="item">The item.</param>
        public NamedItem(string name, TItem item)
        {
            Name = name;
            Item = item;
        }

        /// <summary>
        /// Gets the name.
        /// </summary>
        /// <value>
        /// The name.
        /// </value>
        public string Name { get; set; }

        /// <summary>
        /// Gets the item data.
        /// </summary>
        /// <value>
        /// The item data.
        /// </value>
        public TItem Item { get; set; }

        object INamedItem.Item
        {
            get { return Item; }
        }
    }
}
